﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace CardLogistics.Web.Controls
{
    /// <summary>
    /// HdMisCard 的摘要说明
    /// </summary>
    public class HdMisCard : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string startNO = context.Request.QueryString["startNO"];
            string endNO = context.Request.QueryString["endNO"];
            string rkId = context.Request.QueryString["rkId"];
            string zkId = context.Request.QueryString["zkId"];
            if (rkId=="undefined"|| rkId==null )
                rkId="";
            if (zkId == "undefined" || zkId == null)
                zkId = "";
            if (startNO.Trim().Length == 8 && endNO.Trim().Length == 8)
            {
                string sql = " select Fun_GetMisCard(" + startNO + "," + endNO + ",'" + rkId + "','" + zkId + "') MCard FROM dual ";
                DataTable dt = CardLogistics.DAL.DbHelperSQL.GetQueryResult(sql);
                string retStr = "";
                if (dt != null && dt.Rows.Count > 0)
                    retStr = dt.Rows[0][0].ToString();
                int yyNum = int.Parse(endNO) - int.Parse(startNO) + 1;
                int sjNum = yyNum;
                if (retStr.Trim().Length > 7)
                {
                    sjNum = yyNum - retStr.Split(',').Length;
                }
                //应有数量|实际数量|缺卡卡号
                context.Response.Write(yyNum.ToString()+"|"+sjNum.ToString() + "|" + retStr);
            }
            else
                context.Response.Write("");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}